﻿using System;
using System.Windows.Forms;

namespace lab02
{
    public partial class Form1 : Form
    {
        private BwWithShadows _bwWithShadows1;
        private BwWithShadows _bwWithShadows2;
        private BwWithoutShadows _bwWithoutShadows1;
        private BwWithoutShadows _bwWithoutShadows2;
        private ColorWithShadows _colorWithShadows1;
        private ColorWithShadows _colorWithShadows2;
        private ColorWithoutShadows _colorWithoutShadows1;
        private ColorWithoutShadows _colorWithoutShadows2;
        private IDrawableMatrix _denseMatrix;
        private bool _isDraw;

        private MatrixDrawer _matrixDrawer1;
        private MatrixDrawer _matrixDrawer2;

        private IDrawableMatrix _sparseMatrix;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1Load(object sender, EventArgs e)
        {
            _isDraw = false;

            _colorWithoutShadows1 = new ColorWithoutShadows {Panel = panel1};
            _colorWithoutShadows2 = new ColorWithoutShadows {Panel = panel2};
            _colorWithShadows1 = new ColorWithShadows {Panel = panel1};
            _colorWithShadows2 = new ColorWithShadows {Panel = panel2};
            _bwWithoutShadows1 = new BwWithoutShadows {Panel = panel1};
            _bwWithoutShadows2 = new BwWithoutShadows {Panel = panel2};
            _bwWithShadows1 = new BwWithShadows {Panel = panel1};
            _bwWithShadows2 = new BwWithShadows {Panel = panel2};

            _matrixDrawer1 = _colorWithoutShadows1;
            _matrixDrawer2 = _colorWithoutShadows2;
        }

        private void DrawMe()
        {
            if (!_isDraw) return;
            _denseMatrix.Draw(_matrixDrawer1);
            _sparseMatrix.Draw(_matrixDrawer2);
        }

        private void Button1Click(object sender, EventArgs e)
        {
            _denseMatrix = new DenseMatrix(_width, _height);
            _sparseMatrix = new SparseMatrix(_width, _height);

            MatrixRoutines.Fill(_denseMatrix, 10, 10);

            for (int i = 0; i < _width; i++)
                for (int j = 0; j < _height; j++)
                    _sparseMatrix.SetValue(i, j, _denseMatrix.GetValue(i, j));

            _isDraw = true;

            DrawMe();
        }

        private void RadioButton1CheckedChanged(object sender, EventArgs e)
        {
            _matrixDrawer1 = _colorWithoutShadows1;
            _matrixDrawer2 = _colorWithoutShadows2;
            DrawMe();
        }

        private void RadioButton2CheckedChanged(object sender, EventArgs e)
        {
            _matrixDrawer1 = _colorWithShadows1;
            _matrixDrawer2 = _colorWithShadows2;
            DrawMe();
        }

        private void RadioButton3CheckedChanged(object sender, EventArgs e)
        {
            _matrixDrawer1 = _bwWithoutShadows1;
            _matrixDrawer2 = _bwWithoutShadows2;
            DrawMe();
        }

        private void RadioButton4CheckedChanged(object sender, EventArgs e)
        {
            _matrixDrawer1 = _bwWithShadows1;
            _matrixDrawer2 = _bwWithShadows2;
            DrawMe();
        }
    }
}